package zone.czh.woi.woim.server.channel.handler;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.util.NetUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import zone.czh.woi.protocol.protocol.Payload;
import zone.czh.woi.protocol.util.PayloadUtil;

import java.net.InetSocketAddress;
import java.util.List;
/**
*@ClassName: Barrier
*@Description: None
*@author woi
*/
@ChannelHandler.Sharable
public class Barrier extends MessageToMessageDecoder<Object> {
    private Logger log = LoggerFactory.getLogger(Barrier.class);
    @Override
    protected void decode(ChannelHandlerContext ctx, Object o, List<Object> list) throws Exception {
        log.warn("Block unauthorized channel from ip:{}", NetUtil.getHostname((InetSocketAddress) ctx.channel().remoteAddress()));
        log.warn("Block content:{}",o);
        ctx.channel().writeAndFlush(PayloadUtil.buildPayload("unauthorized", Payload.Cmd.SYS,false));
    }
}
